import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Login from '../views/Login.vue'
import SeatList from '../views/SeatList.vue'
import Seat from '../views/Seat.vue'
import Floor from '../views/Floor.vue'
import ButtonList from '../views/ButtonList.vue'
import SelfInfo from '../views/SelfInfo.vue'
import SearchSeat from '../views/SearchSeat.vue'
import ReservationList from '../views/ReservationList.vue'
import Signin from '../views/Signin.vue'


Vue.use(VueRouter)

const routes = [{
        path: '/',
        name: 'Floor',
        component: Floor,
        meta: { title: '阅览室列表', isleftarrow: false },
    },
    {
        path: '/about',
        name: 'About',
        // route level code-splitting
        // this generates a separate chunk (about.[hash].js) for this route
        // which is lazy-loaded when the route is visited.
        component: () => import( /* webpackChunkName: "about" */ '../views/About.vue')
    },
    {
        path: '/login',
        name: 'Login',
        component: Login,
        meta: { title: '登录', isleftarrow: true }
    },
    {
        path: '/seatlist',
        name: 'SeatList',
        component: SeatList,
        meta: { title: '座位列表', isleftarrow: true },
    },
    {
        path: '/seat',
        name: 'Seat',
        component: Seat,
        meta: { title: '座位预约', isleftarrow: true },
    },
    {
        path: '/btns',
        name: 'ButtonList',
        component: ButtonList,
        meta: { title: 'btns', isleftarrow: true },
    },
    {
        path: '/selfinfo',
        name: 'SelfInfo',
        component: SelfInfo,
        meta: { title: '个人信息', isleftarrow: true },
    },
    {
        path: '/searchseat',
        name: 'SearchSeat',
        component: SearchSeat,
        meta: { title: '筛选座位', isleftarrow: true },
    },
    {
        path: '/reservationlist',
        name: 'ReservationList',
        component: ReservationList,
        meta: { title: '预约记录', isleftarrow: true }
    },
    {
        path: '/signin/:code',
        name: 'Signin',
        component: Signin,
        meta: { title: '二维码签到', isleftarrow: false }
    },
]


const router = new VueRouter({
    mode: 'history',
    base: process.env.BASE_URL,
    routes
})

// 挂载路由导航守卫
// router.beforeEach((to, from, next) => {
//     // 如果是登录页则放行
//     if (to.path === '/login') return next()
//     // 查看token是否存在
//     const token = sessionStorage.getItem('token')
//     if (!token) return next('/login')
//     next()
// })

export default router
